<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件

/**
 * @author mahao 返回数据
 * @param $code 响应码
 * @param $msg  提示语
 * @param $data 放回data
 * @return string json数据格式
 */
function re_json($code=0,$msg='失败',$data=null){
    $json_data = [
        'code' =>$code,
        'msg' => $msg,
        'data' =>$data,
    ];
    echo json_encode($json_data);
    exit();
}

/**
 * @author mahao
 * @version 1  简单过滤 <script></script>
 * @param $filter_arr 传入过滤数组
 * @return $new_data 返回传入的数组
 */
function short_filter($filter_arr){
    $new_data = [];
    foreach($filter_arr as $k=>$v){
        $new_str = preg_replace("/[<,>]/",'!',$v);
        $new_re = preg_replace('/script/','*',$new_str);
        $new_data[$k] = $new_re;
    }
    return $new_data;
}

/**
 * @author mahao
 * @param $length 所需的盐长度
 * @return string 返回字符
 */
function salt($length){
    $round_arr = array_merge(range(0,9),range('a','z'),range('A','Z'));
    $str = '';
    for ($i=0;$i<$length;$i++){
        $rand = mt_rand(0,count($round_arr)-1);
        $str .= $round_arr[$rand];
    }

    return $str;
}


